//启动ui模式
"ui";
//-------------------------------------------------------UI函数------------------------------------------------------------------------
//the main ui
function mainUI() {
    ui.layout(
        <drawer id="drawer">
            <vertical>
                <appbar>
                    <toolbar id="toolbar" title="通灵Gyro" bg="#1E90FF">
                        <vertical id="startvert" clickable="true" bg="?android:attr/selectableItemBackground" margin="0 0 0 0">
                            <img id="startimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_circle_filled_white_black_48dp" tint="#FFFFFF" />
                            <text id="starttext" bg="?android:attr/selectableItemBackground" text="启动" gravity="center" textSize="10" color="#FFFFFF" />
                        </vertical>
                        <vertical id="allopen" clickable="true" bg="?android:attr/selectableItemBackground" margin="0 0 0 0">
                            <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_arrow_black_48dp" tint="#FFFFFF" />
                            <text id="boottext" bg="?android:attr/selectableItemBackground" text="全开" gravity="center" textSize="10" color="#FFFFFF" />
                        </vertical>
                        <vertical id="halfopen" clickable="true" bg="?android:attr/selectableItemBackground" margin="0 0 0 0">
                            <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_circle_outline_black_48dp" tint="#FFFFFF" />
                            <text id="boottext" bg="?android:attr/selectableItemBackground" text="半开" gravity="center" textSize="10" color="#FFFFFF" />
                        </vertical>
                        <vertical id="scrimg" clickable="true" bg="?android:attr/selectableItemBackground" margin="0 0 0 0">
                            <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_perm_media_black_48dp" tint="#FFFFFF" />
                            <text id="boottext" bg="?android:attr/selectableItemBackground" text="图权" gravity="center" textSize="10" color="#FFFFFF" />
                        </vertical>
                        <vertical id="wool" clickable="true" bg="?android:attr/selectableItemBackground" margin="0 0 0 0">
                            <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_grade_black_48dp" tint="#FFFFFF" />
                            <text id="boottext" bg="?android:attr/selectableItemBackground" text="羊毛" gravity="center" textSize="10" color="#FFFFFF" />
                        </vertical>
                        <vertical id="clearbox" clickable="true" bg="?android:attr/selectableItemBackground" margin="0 0 0 0">
                            <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_delete_forever_black_48dp" tint="#FFFFFF" />
                            <text id="boottext" bg="?android:attr/selectableItemBackground" text="清存" gravity="center" textSize="10" color="#FFFFFF" />
                        </vertical>
                    </toolbar>
                    <tabs id="tabs" bg="#1E90FF" />
                </appbar>
                <viewpager id="viewpager" bg="{{backg}}">
                    <frame>
                        <vertical>
                            <card w="auto" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <horizontal >
                                        <img id="startimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_circle_filled_white_black_48dp" tint="#FFFFFF" />
                                        <text text="启动：运行当前页选中脚本的选中功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_arrow_black_48dp" tint="#FFFFFF" />
                                        <text text="全开：运行当前页选中所有脚本所有功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_circle_outline_black_48dp" tint="#FFFFFF" />
                                        <text text="半开：运行当前页选中脚本的所有功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_perm_media_black_48dp" tint="#FFFFFF" />
                                        <text text="图权：申请截图权限，请不要重复启动。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_grade_black_48dp" tint="#FFFFFF" />
                                        <text text="羊毛：启动除了微信抢红包外所有脚本及所有功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_delete_forever_black_48dp" tint="#FFFFFF" />
                                        <text text="清存：停止HUAWEI华为手机所有运行软件" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                </vertical>
                            </card>
                            <card w="auto" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <text text="请您选择蚂蚁森林启动参数(不选软件就不启动，不选功能就登录软件不执行功能,会自动保存上一次的配置，新勾选的功能会变成红色)：" margin="0 0 0 0" textColor="#FFFFFF" layout_gravity="center" />
                                    <radiogroup id='fbName' orientation="horizontal" margin="0 0 0 0" layout_gravity="center">
                                        <radio id="mysl" text='蚂蚁森林' textColor="#FFFFFF" >
                                        </radio>
                                        <radio id="bqdmysl" text='不启动蚂蚁森林' textColor="#FFFFFF">
                                        </radio>
                                    </radiogroup>
                                    <horizontal margin="0 0 0 0">
                                        <pref-checkbox id="myysbk" text="双倍卡" textColor="#FFFFFF" />
                                        <pref-checkbox id="myynlz" text="能量罩" textColor="#FFFFFF" />
                                        <pref-checkbox id="myhzjs" text="合种浇水" textColor="#FFFFFF" />
                                        <pref-checkbox id="none" text="敬请期待" textColor="#FFFFFF" />
                                    </horizontal>
                                </vertical>
                            </card>
                            <card w="auto" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <text text="请您选择芭芭农场启动参数(不选软件就不启动，不选功能就登录软件不执行功能,会自动保存上一次的配置，新勾选的功能会变成红色)：" textColor="#FFFFFF" layout_gravity="center" />
                                    <radiogroup id='fbName' orientation="horizontal" margin="0 0 0 0" layout_gravity="center">
                                        <radio id="bbnc" text='芭芭农场' textColor="#FFFFFF" >
                                        </radio>
                                        <radio id="bqdbbnc" text='不启动芭芭农场' textColor="#FFFFFF">
                                        </radio>
                                    </radiogroup>
                                    <horizontal margin="0 0 0 0">
                                        <pref-checkbox id="sqgs" text="收果实" textColor="#FFFFFF" />
                                        <pref-checkbox id="bbbxrw" text="找宝箱" textColor="#FFFFFF" />
                                        <pref-checkbox id="bbllrw" text="浏览任务" textColor="#FFFFFF" />
                                        <pref-checkbox id="mftq" text="蜜蜂偷取" textColor="#FFFFFF" />
                                    </horizontal>
                                </vertical>
                            </card>
                        </vertical>
                    </frame>
                    <frame>
                        <vertical>
                            <card w="auto" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <horizontal >
                                        <img id="startimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_circle_filled_white_black_48dp" tint="#FFFFFF" />
                                        <text text="启动：运行当前页选中脚本的选中功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_arrow_black_48dp" tint="#FFFFFF" />
                                        <text text="全开：运行当前页选中所有脚本所有功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_circle_outline_black_48dp" tint="#FFFFFF" />
                                        <text text="半开：运行当前页选中脚本的所有功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_perm_media_black_48dp" tint="#FFFFFF" />
                                        <text text="图权：申请截图权限，请不要重复启动。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_grade_black_48dp" tint="#FFFFFF" />
                                        <text text="羊毛：启动除了微信抢红包外所有脚本及所有功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_delete_forever_black_48dp" tint="#FFFFFF" />
                                        <text text="清存：停止HUAWEI华为手机所有运行软件" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                </vertical>
                            </card>
                            <card w="auto" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <text text="请您选择农行掌银启动参数(不选软件就不启动)：" margin="0 0 0 0" textColor="#FFFFFF" layout_gravity="center" />
                                    <radiogroup id='fbName' orientation="horizontal" margin="0 0 0 0" layout_gravity="center">
                                        <radio id="nhzylxd" text='农行掌银领小豆' textColor="#FFFFFF" >
                                        </radio>
                                        <radio id="bqdnhzy" text='不启动农行掌银' textColor="#FFFFFF">
                                        </radio>
                                    </radiogroup>
                                    <text text="请设置你的农行掌银密码(只用输入一次，之后会存在sqlite数据库中，每次查，默认为lt123456)：" textStyle="bold" margin="0 0 0 0" textColor="#FF0000" layout_gravity="center" />
                                    <horizontal margin="0 0 0 0">
                                        <input id="pd" text="请输入你的密码(点击清除内容)" textColor="#FFFFFF" />
                                        <colored-button id="commit" w="auto" h="auto" text="保存" color="#3CB371" textColor="#FFFFFF" style="Widget.AppCompat.Button.Colored" />
                                    </horizontal>
                                </vertical>
                            </card>
                            <card w="*" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <text textStyle="bold" text="请不要设置手势密码" margin="0 0 0 0" textColor="#FF0000" layout_gravity="center" />
                                    <text text="请您选择云闪付启动参数(不选软件就不启动)：" margin="0 0 0 0" textColor="#FFFFFF" layout_gravity="center" />
                                    <radiogroup id='fbName' orientation="horizontal" margin="0 0 0 0" layout_gravity="center">
                                        <radio id="ysfqd" text='云闪付签到' textColor="#FFFFFF" >
                                        </radio>
                                        <radio id="bqdysf" text='不启动云闪付' textColor="#FFFFFF">
                                        </radio>
                                    </radiogroup>
                                </vertical>
                            </card>
                        </vertical>
                    </frame>
                    <frame>
                        <vertical>
                            <card w="auto" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <horizontal>
                                        <img id="startimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_circle_filled_white_black_48dp" tint="#FFFFFF" />
                                        <text text="启动：运行当前页选中脚本的选中功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal>
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_arrow_black_48dp" tint="#FFFFFF" />
                                        <text text="全开：运行当前页选中所有脚本所有功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal>
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_circle_outline_black_48dp" tint="#FFFFFF" />
                                        <text text="半开：运行当前页选中脚本的所有功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal>
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_perm_media_black_48dp" tint="#FFFFFF" />
                                        <text text="图权：申请截图权限，请不要重复启动。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal>
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_grade_black_48dp" tint="#FFFFFF" />
                                        <text text="羊毛：启动除了微信抢红包外所有脚本及所有功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal>
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_delete_forever_black_48dp" tint="#FFFFFF" />
                                        <text text="清存：清HUAWEI除华为手机所有软件缓存" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
-                                    </horizontal>
                                    <text text="没有安装auto.js 4.1.0不要启动该功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    <horizontal>
                                        <colored-button id="wxhbstartbtn" text="开始" color="#00DD00" />
                                        <colored-button id="wxhbendbtn" text="停止" color="#FF0000" />
                                    </horizontal>
                                </vertical>
                            </card>
                        </vertical>
                    </frame>
                </viewpager>
            </vertical>
            <vertical layout_gravity="left" bg="#ffffff" w="280">
                <img w="280" h="200" scaleType="fitXY" src="file://res/雪中对饮.png" />
                <list id="menu">
                    <horizontal bg="?selectableItemBackground" w="*">
                        <img w="50" h="50" padding="16" src="{{this.icon}}" tint="{{color}}" />
                        <text textColor="black" textSize="15sp" text="{{this.title}}" layout_gravity="center" />
                    </horizontal>
                </list>
            </vertical>
        </drawer>
    );
    //清除缓存
    ui.clearbox.on("click", function() {
        recents()
        threads.start(function() {
            id("com.huawei.android.launcher:id/clear_all_recents_image_button").findOne().click()
        })
    })
    //设置顶部颜色
    ui.statusBarColor(color);
    //创建选项菜单(右上角)
    ui.emitter.on("create_options_menu", menu => {
        menu.add("设置");
        menu.add("关于");
    });
    //监听选项菜单点击
    ui.emitter.on("options_item_selected", (e, item) => {
        switch (item.getTitle()) {
            case "设置":
                toast("还没有设置,预计会做手机型号选择，现在只支持华为");
                break;
            case "关于":
                alert("关于", "目前还有很多不足，我会抽空努力完善的！有问题可以随时联系我微信：This_my_last_gyro");
                break;
        }
        e.consumed = true;
    });
    activity.setSupportActionBar(ui.toolbar);
    //设置滑动页面的标题
    ui.viewpager.setTitles(["阿里软件", "金融软件", "腾讯软件"]);
    //让滑动页面和标签栏联动
    ui.tabs.setupWithViewPager(ui.viewpager);

    //让工具栏左上角可以打开侧拉菜单
    ui.toolbar.setupWithDrawer(ui.drawer);
    //set the data source of list
    ui.menu.setDataSource([{
            title: "检测安卓版本",
            icon: "@drawable/ic_android_black_48dp"
        },
        {
            title: "开启无障碍服务",
            icon: "@drawable/ic_settings_black_48dp"
        },
        {
            title: "主题与皮肤",
            icon: "@drawable/ic_favorite_black_48dp"
        },
        {
            title: "检测手机分辨率",
            icon: "@drawable/ic_stay_current_landscape_black_48dp"
        },
        {
            title: "检测手机品牌",
            icon: "@drawable/ic_stay_current_portrait_black_48dp"
        },
        {
            title: "我的b站主页（欢迎一起学习）",
            icon: "@drawable/ic_format_bold_black_48dp"
        },
        {
            title: "查看参数数据库",
            icon: "@drawable/ic_build_black_48dp"
        },
        {
            title: "隐藏参数数据库",
            icon: "@drawable/ic_build_black_48dp"
        },
        {
            title: "退出",
            icon: "@drawable/ic_exit_to_app_black_48dp"
        }
    ]);
    //set the different case invoking different function
    ui.menu.on("item_click", item => {
        switch (item.title) {
            case "退出":
                ui.finish();
                break;
            case "检测安卓版本":
                toastLog("安卓" + device.release);
                break;
            case "检测手机分辨率":
                toastLog(device.width + "*" + device.height);
                break;
            case "检测手机品牌":
                toastLog(device.brand);
                break;
            case "我的b站主页（欢迎一起学习）":
                biliUI();
                break;
            case "主题与皮肤":
                themeUI();
                break;
            case "查看参数数据库":
                console.clear();
                console.log("蚂蚁森林：");
                //logging the maiyisenlin setting that was selected from db
                console.log(db.rawQuery("SELECT * FROM MYSL", null).all()[0]);
                console.log("农行掌银：");
                //logging the ABC mobile bank setting that was selected from db
                console.log(db.rawQuery("SELECT * FROM ABCZY", null).all()[0]);
                console.show();
                break;
            case "隐藏参数数据库":
                console.hide();
                break;
            case "开启无障碍服务":
                app.startActivity({
                    action: "android.settings.ACCESSIBILITY_SETTINGS"
                });
                toastLog("请给我无障碍服务权限");
                break;
        }
    })

    //功能参数选择消息提示气泡------------------------------------------------------------------------------------
    ui.mysl.on("check", () => {
        if (className("android.widget.RadioButton").text("蚂蚁森林").findOnce().checked()) {
            ui.mysl.setTextColor(colors.parseColor("#FF0000"));
            toastLog("你选择了将要启动蚂蚁森林脚本");
        } else {
            ui.mysl.setTextColor(colors.parseColor("#FFFFFF"));
            toastLog("你取消了蚂蚁森林脚本");
        }
    })
    //农行掌银领小豆
    ui.nhzylxd.on("check", () => {
        if (className("android.widget.RadioButton").text("农行掌银领小豆").findOnce().checked()) {
            ui.nhzylxd.setTextColor(colors.parseColor("#FF0000"));
            toastLog("你选择了将要启动农行掌银领小豆脚本");
        } else {
            ui.nhzylxd.setTextColor(colors.parseColor("#FFFFFF"));
            toastLog("你取消了农行掌银领小豆脚本");
        }
    })
    //蚂蚁森林
    ui.myhzjs.on("check", () => {
        if (className("android.widget.CheckBox").text("合种浇水").findOnce().checked()) {
            ui.myhzjs.setTextColor(colors.parseColor("#FF0000"));
            toastLog("你选择了合种浇水参数");
            //update set watering=true where id = 1
            db.update("MYSL", {
                watering: true
            }, "ID = ?", [1])
            // toastLog(db.rawQuery("SELECT * FROM MYSL", null).all())
            // obj = db.rawQuery("SELECT * FROM MYSL where id =?", ["1"]).single()
            // toastLog(typeof obj.shield)
        } else {
            ui.myhzjs.setTextColor(colors.parseColor("#FFFFFF"));
            toastLog("你取消了合种浇水参数");
            //update set watering=false where id = 1
            db.update("MYSL", {
                watering: false
            }, "ID = ?", [1])
            // toastLog(db.rawQuery("SELECT * FROM MYSL", null).all())
            // obj = db.rawQuery("SELECT * FROM MYSL where id =?", ["1"]).single()
            // toastLog(typeof obj.shield)
        }
    })
    ui.myysbk.on("check", () => {
        if (className("android.widget.CheckBox").text("双倍卡").findOnce().checked()) {
            ui.myysbk.setTextColor(colors.parseColor("#FF0000"));
            toastLog("你选择了双倍卡参数");
            //update set doublecard=true where id = 1
            db.update("MYSL", {
                doublecard: true
            }, "ID = ?", [1])
        } else {
            ui.myysbk.setTextColor(colors.parseColor("#FFFFFF"));
            toastLog("你取消了双倍卡参数");
            //update set doublecard=false where id = 1
            db.update("MYSL", {
                doublecard: false
            }, "ID = ?", [1])
        }
    })
    ui.myynlz.on("check", () => {
        if (className("android.widget.CheckBox").text("能量罩").findOnce().checked()) {
            ui.myynlz.setTextColor(colors.parseColor("#FF0000"));
            toastLog("你选择了能量罩参数");
            //update set shield=true where id = 1
            db.update("MYSL", {
                shield: true
            }, "ID = ?", [1])
        } else {
            ui.myynlz.setTextColor(colors.parseColor("#FFFFFF"));
            toastLog("你取消了能量罩参数");
            //update set shield=false where id = 1
            db.update("MYSL", {
                shield: false
            }, "ID = ?", [1])
        }
    })
    //农行小豆
    ui.pd.on("click", function() {
        ui.pd.setText("")
    })
    ui.commit.on("click", function() {
        db.update("ABCZY", {
            password: className("android.widget.EditText").findOnce().text()
        }, "id=?", [1]);
        toastLog("修改成功")
    })
    //启动函数
    ui.startvert.on("click", function() {
        if (className("android.widget.TextView").text("启动").exists()) {
            ui.startimg.setSource("@drawable/ic_pause_circle_filled_black_48dp");
            ui.starttext.setText("暂停");
            toastLog("运行当前选择的脚本");
            if (text("阿里软件").findOnce().selected() && className("android.widget.RadioButton").text("芭芭农场").findOnce().checked()) {
                engines.execScriptFile("./res/FuncCollection/芭芭农场领阳光.js");
            } else if (text("阿里软件").findOnce().selected() && className("android.widget.RadioButton").text("蚂蚁森林").findOnce().checked()) {
                engines.execScriptFile("./res/FuncCollection/新版蚂蚁森林.js")
            } else if (text("金融软件").findOnce().selected() && className("android.widget.RadioButton").text("农行掌银领小豆").findOnce().checked()) {
                toastLog("Link start!( ˃̶̤́ ꒳ ˂̶̤̀ )")
                engines.execScriptFile("./res/FuncCollection/农行小豆.js");
            } else if (text("金融软件").findOnce().selected() && className("android.widget.RadioButton").text("云闪付签到").findOnce().checked()) {
                toastLog("Link start!( ˃̶̤́ ꒳ ˂̶̤̀ )")
                engines.execScriptFile("./res/FuncCollection/云闪付签到.js");
            }
        } else if (className("android.widget.TextView").text("暂停").exists()) {
            ui.startimg.setSource("@drawable/ic_play_circle_filled_white_black_48dp");
            ui.starttext.setText("启动");
            threads.shutDownAll();
            toastLog("停止所有运行的脚本");
        }
    })
    ui.allopen.on("click", function() {
        if (text("阿里软件").findOnce().selected()) {
            toastLog("Link start!( ˃̶̤́ ꒳ ˂̶̤̀ )");
            engines.execScriptFile("./res/FuncCollection/新版蚂蚁森林.js")
            if (text("通灵Gyro").exists()) {
                engines.execScriptFile("./res/FuncCollection/芭芭农场领阳光.js");
            }
        } else if (text("金融软件").selected()) {
            toastLog("Link start!( ˃̶̤́ ꒳ ˂̶̤̀ )");
            engines.execScriptFile("./res/FuncCollection/农行小豆.js");
            if (text("通灵Gyro").exists()) {
                engines.execScriptFile("./res/FuncCollection/云闪付签到.js");
            }
        }
    })
    ui.scrimg.on("click", function() {
        try {
            threads.start(function() {
                text("立即开始").findOne().click();
            });
            threads.start(function() {
                images.requestScreenCapture(); //向系统省去截图权限
            })
            let err = new Error
            err.name = "截图权限已开启"
            err.message = "你已经打开截图权限请不要重复提交"
            throw err
        } catch (err) {
            toastLog(err, err.name, err.message);
        }
    })
    ui.clearbox.on("cilck", function() {
        toastLog("hello")
    });
    ui.wxhbstartbtn.on("click", function() {
        toastLog("Link start!( ˃̶̤́ ꒳ ˂̶̤̀ )")
        app.launchApp("Auto.js")
    })
}
//the webview ui about bilibili
function biliUI() {
    ui.layout(
        <frame>
            <horizontal bg="{{color}}">
                <colored-button id="backbtn" color="{{color}}" text="返回Gyro" />
            </horizontal>
            <horizontal>
                <webview id="webview" margin="0 60 0 0" />
            </horizontal>
        </frame>
    )
    ui.webview.loadUrl("https://m.bilibili.com/space/166269644");
    ui.backbtn.on("click", () => mainUI())
}
//the theme ui about settings
function themeUI() {
    ui.layout(
        <scroll>
            <vertical bg="#707070" padding="16">
                <colored-button id="backbtn" text="返回Gyro" color="#707070" />
                <text text="皮肤：" textColor="black" textSize="16sp" marginTop="16" />
                <horizontal>
                    <vertical id="侧颜" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="侧颜" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/侧颜.jpg"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                    <vertical id="烟火" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="烟火" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/烟火.jpg"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                    <vertical id="星尘斗士" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="星尘斗士" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/JOJO.jpg"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                    <vertical id="圣女贞德" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="圣女贞德" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/贞德.jpeg"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                </horizontal>
                <horizontal>
                    <vertical id="沉默" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="沉默" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/沉默.png"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                    <vertical id="春色" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="春色" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/春色.png"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                    <vertical id="躲避" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="躲避" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/躲避.jpg"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                    <vertical id="离别的春季" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="离别的春季" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/离别的春季.jpg"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                </horizontal>
                   <horizontal>
                    <vertical id="落霞" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="落霞" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/落霞.jpg"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                    <vertical id="内心下着雨" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="内心下着雨" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/内心下着雨.png"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                    <vertical id="尼康" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="尼康" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/尼康.png"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                    <vertical id="世界的半径" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="世界的半径" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/世界的半径.png"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                </horizontal>
                   <horizontal>
                    <vertical id="世界终焉" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="世界终焉" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/世界终焉.png"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                    <vertical id="是谁的谁" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="是谁的谁" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/是谁的谁.png"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                    <vertical id="送花" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="送花" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/送花.png"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                    <vertical id="夏季少女" w="80" h="120" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="夏季少女" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/夏季少女.jpg"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                </horizontal>
                <text text="名片卡：" textColor="black" textSize="16sp" marginTop="16" />
                <horizontal>
                    <vertical w="80" h="80" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="雪中对饮" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <img src="file://res/雪中对饮.png" circle="true"
                        borderWidth="2dp" borderColor="#202020" />
                    </vertical>
                </horizontal>
                <text text="主题颜色：" textColor="black" textSize="16sp" marginTop="16" />
                <horizontal>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="纯黑" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#000000" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="骚粉" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#FFB6C1" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="原谅" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#3CB371" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="天空" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#00BFFF" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="基佬" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#9400D3" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="白云" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#FFFFFF" />
                    </vertical>
                </horizontal>
                <horizontal>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="纯黑" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#000000" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="骚粉" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#FFB6C1" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="原谅" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#3CB371" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="天空" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#00BFFF" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="基佬" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#9400D3" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="白云" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#FFFFFF" />
                    </vertical>
                </horizontal>
                <text text="提醒字体颜色：" textColor="black" textSize="16sp" marginTop="16" />
                <horizontal>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="纯黑" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#000000" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="骚粉" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#FFB6C1" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="原谅" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#3CB371" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="天空" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#00BFFF" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="基佬" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#9400D3" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="白云" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#FFFFFF" />
                    </vertical>
                </horizontal>
                <text text="常规字体颜色：" textColor="black" textSize="16sp" marginTop="16" />
                <horizontal>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="纯黑" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#000000" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="骚粉" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#FFB6C1" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="原谅" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#3CB371" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="天空" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#00BFFF" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="基佬" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#9400D3" />
                    </vertical>
                    <vertical w="50" h="90" clickable="true" bg="?android:attr/selectableItemBackground">
                        <text text="白云" textColor="black" textSize="16sp" marginTop="16" gravity="center" />
                        <text w="50" h="50" bg="#FFFFFF" />
                    </vertical>
                </horizontal>
            </vertical>
        </scroll>
    );
    ui.backbtn.on("click", () => mainUI())
}
//-------------------------------------------------------主函数部分--------------------------------------------------------------------
//调用js文件
var PrefCheckBox = require('./uisetting.js');
var Func = require('./func.js')
var color = "#1E90FF";
var backg = "file://res/侧颜.jpg"
threads.start(function() {
    auto.waitFor(); //判断是否启动无障碍服务
    text("立即开始").findOne().click();
});
threads.start(function() {
    images.requestScreenCapture(); //向系统省去截图权限
})
// 创建或打开一个数据库文件，在当前目录的data.db文件，用来存储选择的参数
var db = sqlite.open("./data.db", {
    version: 1
}, {
    onOpen: function(db) {
        // 数据库打开时，执行创建数据库表的语句
        // 设计的表名为MYSL(蚂蚁森林)，字段如下:
        // id: 整数，自增，键
        // shield: 能量盾，整数，非空
        // watering: 浇水，整数，非空
        // doublecard: 双倍卡，整数，非空
        db.execSQL("CREATE TABLE IF NOT EXISTS MYSL(" +
            "`id` INTEGER PRIMARY KEY AUTOINCREMENT, " +
            "`shield` BOOLEAN NOT NULL, " +
            "`watering` BOOLEAN NOT NULL," +
            "`doublecard` BOOLEAN NOT NULL" +
            ")");
    }
});
//invoking the mainUI function
mainUI()